using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Credit_Identify_company : Member, IRequiresSessionState
{
	public string Action = "";
	public int IdentifyType = 2;
	protected ScriptManager ScriptManager1;
	protected UserControls_cmpy_Top Top1;
	protected Literal UserName;
	protected TextBox CompanyName;
	protected RequiredFieldValidator RequiredFieldValidator3;
	protected RadioButtonList CompanyType;
	protected Shop_UserControls_HowaveProvinceCity HowaveProvinceCity1;
	protected TextBox CompanyAddrss;
	protected TextBox LienceName;
	protected RequiredFieldValidator rfv7;
	protected TextBox CompanyRange;
	protected RequiredFieldValidator rfv6;
	protected TextBox LienceNum;
	protected RegularExpressionValidator rfv2;
	protected TextBox ContacterName;
	protected RequiredFieldValidator rfv1;
	protected TextBox ContacterIDNum;
	protected RegularExpressionValidator rev9;
	protected RequiredFieldValidator rfv4;
	protected TextBox ContacterPhone;
	protected RequiredFieldValidator rfv5;
	protected RegularExpressionValidator rev10;
	protected TextBox ContacterMobilePhone;
	protected RegularExpressionValidator rex1;
	protected TextBox Email;
	protected RegularExpressionValidator EmailReq;
	protected TextBox Fax;
	protected RegularExpressionValidator faxText;
	protected FileUpload FileUpload1;
	protected HiddenField hfUploadPicPath;
	protected Button UpLoadButton;
	protected Label UploadPicMsg;
	protected Label UploadPanel;
	protected Image IDPhoto;
	protected Label err_tips;
	protected Button SaveInfo;
	protected Button btnSavaImg;
	protected UserControls_CMYP_Foot Foot1;
	protected HtmlForm form1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.UserName.Text = base.user.UserName;
		string sql = "Select Count(IdentifyID) From [HLShop_Application] Where IdentifyType=2 and UserID=" + base.user.UserID;
		if (this.conn.ExecuteCount(sql) > 0)
		{
			this.Action = "Modify";
		}
		if (!base.IsPostBack)
		{
			this.FileUpload1.Attributes.Add("onchange", "return SavePic('" + this.btnSavaImg.ClientID + "')");
			if (this.conn.ExecuteCount("Select Count(UserInfoID) From [HL_UserInfo] Where UserID=" + base.user.UserID) <= 0)
			{
				this.WriteErrMsg("", Language.Get("PassPort/NotUserInfo"), "/Member/Index.aspx?mainurl=Shop_UserInfoList.aspx");
			}
			this.HowaveProvinceCity1.SelectedProvince = base.user.UserInforRes["Province"].ToString();
			this.HowaveProvinceCity1.SelectedCity = base.user.UserInforRes["City"].ToString();
			this.HowaveProvinceCity1.SelectedArea = base.user.UserInforRes["CMArea"].ToString();
			if (this.Action == "Modify")
			{
				this.InitUserMifiy();
			}
		}
	}
	protected void InitUserMifiy()
	{
		int userID = base.user.UserID;
		Shop_Application shop_Application = new Shop_Application(this.conn);
		DataTable applicationByUserIDType = shop_Application.GetApplicationByUserIDType(userID, this.IdentifyType);
		if (applicationByUserIDType != null && applicationByUserIDType.Rows.Count >= 1)
		{
			string[] contentArray = applicationByUserIDType.Rows[0]["IdentifyDetail"].ToString().Split(new char[]
			{
				'$'
			});
			string a = applicationByUserIDType.Rows[0]["Status"].ToString();
			string text = Shop_Application.GetContentByName("CompanylicenseUpload", contentArray);
			if (string.IsNullOrEmpty(text) || text.Trim() == "")
			{
				text = "../images/show_nopic.gif";
			}
			this.hfUploadPicPath.Value = text;
			this.IDPhoto.ImageUrl = text;
			this.IDPhoto.Attributes.Add("onClick", "{location.href='" + this.IDPhoto.ImageUrl + "'}");
			this.UserName.Text = applicationByUserIDType.Rows[0]["UserName"].ToString();
			this.CompanyName.Text = Shop_Application.GetContentByName("CompanyName", contentArray);
			this.CompanyType.SelectedValue = Shop_Application.GetContentByName("CompayType", contentArray);
			this.LienceName.Text = Shop_Application.GetContentByName("CompanylicenseName", contentArray);
			this.HowaveProvinceCity1.SelectedProvince = Shop_Application.GetContentByName("CompanyProvince", contentArray);
			this.HowaveProvinceCity1.SelectedCity = Shop_Application.GetContentByName("CompanyCity", contentArray);
			this.HowaveProvinceCity1.SelectedArea = Shop_Application.GetContentByName("CompanyArea", contentArray);
			this.CompanyAddrss.Text = Shop_Application.GetContentByName("CompanyAddress", contentArray);
			this.CompanyRange.Text = Shop_Application.GetContentByName("CompanyRange", contentArray);
			this.LienceNum.Text = Shop_Application.GetContentByName("CompanylicenseNum", contentArray);
			this.ContacterName.Text = Shop_Application.GetContentByName("ContacterName", contentArray);
			this.ContacterPhone.Text = Shop_Application.GetContentByName("ContacterPhone", contentArray);
			this.ContacterMobilePhone.Text = Shop_Application.GetContentByName("ContacterMobile", contentArray);
			this.Email.Text = Shop_Application.GetContentByName("ContacterEmail", contentArray);
			this.Fax.Text = Shop_Application.GetContentByName("ContacterFax", contentArray);
			this.ContacterIDNum.Text = Shop_Application.GetContentByName("ContacterIDCardNum", contentArray);
			if (a == "0" || a == "9" || a == "-1")
			{
				this.SaveInfo.Enabled = true;
			}
			else
			{
				this.SaveInfo.Enabled = false;
			}
		}
	}
	protected void SaveInfo_Click(object sender, EventArgs e)
	{
		if (this.Action == "Pass")
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Ventify/NotModify", new string[0]), "");
		}
		int userID = base.user.UserID;
		string userName = base.user.UserName;
		string text = this.CompanyName.Text;
		string selectedValue = this.CompanyType.SelectedValue;
		string text2 = this.LienceName.Text;
		string selectedProvince = this.HowaveProvinceCity1.SelectedProvince;
		string companyCity = "";
		string companyArea = "";
		if (!string.IsNullOrEmpty(selectedProvince))
		{
			companyCity = this.HowaveProvinceCity1.SelectedCity;
			companyArea = this.HowaveProvinceCity1.SelectedArea;
		}
		string text3 = this.CompanyAddrss.Text;
		string text4 = this.CompanyRange.Text;
		string text5 = this.LienceNum.Text;
		string text6 = this.ContacterName.Text;
		string text7 = this.ContacterIDNum.Text;
		string text8 = this.ContacterPhone.Text;
		string text9 = this.ContacterMobilePhone.Text;
		string text10 = this.Email.Text;
		string text11 = this.Fax.Text;
		string value = this.hfUploadPicPath.Value;
		Shop_Application shop_Application = new Shop_Application(this.conn);
		string identifyDetail = shop_Application.AddCompanyIdentifyDetail(text, text2, text5, text6, text3, text8, text9, text11, text3, selectedProvince, companyCity, text7, selectedValue, text4, value, text10, companyArea);
		bool flag;
		if (this.Action == "Modify")
		{
			if ((value == "" || value == null) && this.FileUpload1.PostedFile.FileName != "")
			{
				this.WriteErrMsg("", Language.GetMemberMsg("Ventify/UploadFail", new string[0]), "");
			}
			DataTable applicationByUserIDType = shop_Application.GetApplicationByUserIDType(userID, this.IdentifyType);
			if (applicationByUserIDType != null && applicationByUserIDType.Rows.Count >= 1)
			{
				int identifyID = int.Parse(applicationByUserIDType.Rows[0]["IdentifyID"].ToString());
				flag = shop_Application.ModifyApplication(identifyID, userID, userName, this.IdentifyType, identifyDetail, "", value);
			}
			else
			{
				flag = shop_Application.AddApplication(userID, userName, this.IdentifyType, identifyDetail, "", value);
			}
		}
		else
		{
			if (value == "" || value == null)
			{
				this.WriteErrMsg("", Language.GetMemberMsg("Ventify/UploadFail", new string[0]), "");
			}
			flag = shop_Application.AddApplication(userID, userName, this.IdentifyType, identifyDetail, "", value);
		}
		if (flag)
		{
			this.WriteSuccessMsg("", Language.GetMemberMsg("Ventify/IDVentifing", new string[0]), "/Member/Index.aspx?mainurl=Shop_Identify.aspx");
		}
		else
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/Fail", new string[]
			{
				""
			}), "");
		}
	}
	protected void btnSavaImg_Click(object sender, EventArgs e)
	{
		this.hfUploadPicPath.Value = this.UploadPhoto();
		this.IDPhoto.ImageUrl = "..\\" + this.hfUploadPicPath.Value;
	}
	protected string UploadPhoto()
	{
		int contentLength = this.FileUpload1.PostedFile.ContentLength;
		string result;
		if (contentLength > 120000)
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Ventify/UploadTooBig", new string[]
			{
				"120K"
			}), "");
		}
		else
		{
			if (contentLength <= 0 || this.FileUpload1.PostedFile.FileName == "")
			{
				result = "";
				return result;
			}
		}
		string text = this.FileUpload1.PostedFile.FileName;
		text = text.Substring(text.LastIndexOf("."));
		if (text.ToUpper() != ".JPG" && text.ToUpper() != ".GIF" && text.ToUpper() != ".PNG")
		{
			this.WriteErrMsg("", "营业执照图片格式不正确！(图片格式为JPG、GIF、PNG)", "");
		}
		text = "Company_" + base.user.UserID + text;
		string str = "\\UploadFile\\CompanyLience\\";
		UpLoadFile upLoadFile = new UpLoadFile();
		upLoadFile.Suffix = "gif|jpg|jpeg|bmp";
		upLoadFile.myfile = this.FileUpload1;
		bool flag = upLoadFile.UpLoad(str + text);
		if (flag)
		{
			result = str + text;
		}
		else
		{
			this.WriteErrMsg("", Language.Get("Common/Fail", upLoadFile.ErrString), "");
			result = "";
		}
		return result;
	}
	protected void UpdoadPic_Click(object sender, EventArgs e)
	{
		string text = this.UploadPhoto();
		if (text != null && text != "")
		{
			this.UploadPicMsg.Text = "成功上传图片";
			this.hfUploadPicPath.Value = text;
			this.IDPhoto.ImageUrl = "../" + text;
		}
		else
		{
			this.UploadPicMsg.Text = "图片上传失败";
			this.hfUploadPicPath.Value = "";
		}
	}
}
